#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

int maxCoins(vector<int>& piles) {
    
    sort(piles.begin(), piles.end());
    int n = piles.size() / 3;
    int max = 0;
    for (int i = n; i < piles.size(); i+=2) {
        max += piles[i];
    }
    return max;

}

int main() {
    vector<int> piles = {9,8,7,6,5,1,2,3,4};
    cout << maxCoins(piles) << endl;
    return 0;
}